import React, { FC, useEffect, useState } from 'react'
import { useCountDown } from 'ahooks';
import { useNavigate } from 'react-router-dom';

const useTimeDown = (time: any = 5000, onEnd?: any, interval: any = 1000) => {
    const router = useNavigate()
    const [targetDate, setTargetDate] = useState<number>();
    const [countdown] = useCountDown({
        targetDate,
        onEnd: onEnd,
        interval
    });

    useEffect(() => {
        setTargetDate(Date.now() + time)
    }, [])
    return [
        Math.ceil(countdown / interval)
    ]
}

export default useTimeDown